﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Presentation.Module.Setup.Interfaces.Services;
using Application.Interfaces;

namespace Presentation.Module.Setup.Services
{
    public class SkillsService : ISkillsService
    {
        public SkillsService(ISetupManagementService setupManagementService)
        {
            this.SetupManagementService = setupManagementService;

            this.SkillMapper = new VPL.Mapper.Mapper<Models.Skill, Domain.Setup.Entities.Skill>();
            TaskMapper = new VPL.Mapper.Mapper<Models.Task, Domain.Setup.Entities.Task>();
            TaskMapper.CreateMap<Models.Skill, Domain.Setup.Entities.Skill>();
        }

        public ISetupManagementService SetupManagementService { get; set; }

        public VPL.Mapper.Mapper<Models.Skill, Domain.Setup.Entities.Skill> SkillMapper { get; set; }
        public VPL.Mapper.Mapper<Models.Task, Domain.Setup.Entities.Task> TaskMapper { get; set; }

        public List<Models.Skill> GetAllSkills()
        {
            return SkillMapper.Map(SetupManagementService.GetAllSkills()).ToList();
        }

        public void EditSkill(Models.Skill skill)
        {
            SetupManagementService.UpdateSkill(SkillMapper.Map(skill));
        }

        public void RemoveSkill(Models.Skill skill)
        {
            SetupManagementService.DeleteSkill(SkillMapper.Map(skill));
        }

        public Models.Skill AddSkill(Models.Skill skill)
        {
            return
                SkillMapper.Map(SetupManagementService.AddSkill(SkillMapper.Map(skill))); ;
        }


        public List<Models.Task> GetAllTasksForSkill(Models.Skill skill)
        {
            return
                TaskMapper.Map(SetupManagementService.GetAllTasksForSkill(SkillMapper.Map(skill))).ToList();
        }

        public void EditTask(Models.Task task)
        {
            this.SetupManagementService.UpdateTask(TaskMapper.Map(task));
        }

        public void RemoveTask(Models.Task task)
        {
            this.SetupManagementService.DeleteTask(TaskMapper.Map(task));
        }

        public Models.Task AddTask(Models.Task task)
        {
            var mappedTask = TaskMapper.Map(task);            

            return
                TaskMapper.Map(this.SetupManagementService.AddTask(mappedTask, task.RequiredSkillId));
        }
    }
}
